package student.aistar.day05;

import java.util.Calendar;
import java.util.Date;

public class CalendarDemo {
    public static void main(String[] args) {
        //超纲 - abstract是修饰符 - 修饰类 - 抽象的类
        //特点 - 不能被new[不能够被实例化, 具体化]
        //Calendar cal = new Calendar();//error

        Calendar cal = Calendar.getInstance();
        System.out.println(cal);//java.util.GregorianCalendar[time=1626832105935,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Asia/Shanghai",offset=28800000,dstSavings=0,useDaylight=false,transitions=29,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2021,MONTH=6,WEEK_OF_YEAR=30,WEEK_OF_MONTH=4,DAY_OF_MONTH=21,DAY_OF_YEAR=202,DAY_OF_WEEK=4,DAY_OF_WEEK_IN_MONTH=3,AM_PM=0,HOUR=9,HOUR_OF_DAY=9,MINUTE=48,SECOND=25,MILLISECOND=935,ZONE_OFFSET=28800000,DST_OFFSET=0]


        //统一设置值
        cal.set(2021, 6, 21);
        Date date = cal.getTime();//获得Date对象
        System.out.println(date);


        //Date -> Calendar
        Date d = new Date();
        cal.setTime(d);
        System.out.println(cal.get(1));


        System.out.println("=======单个字段一一赋值==========");
        Calendar cd = Calendar.getInstance();
        //以下这些属性如果都不设置的话, 会按照系统默认时间设置
        cd.set(Calendar.YEAR, 2020);
        cd.set(Calendar.MONTH, 6);
        cd.set(Calendar.DAY_OF_MONTH, 21);//设置几号,

        int year = cd.get(1);
        System.out.println("year: "+year);
        System.out.println("month: "+ cd.get(Calendar.MONTH));
        System.out.println("date: "+ cd.get(Calendar.DAY_OF_MONTH));
    }
}
